﻿Imports Control_Vuelos_BL
Imports Control_Vuelos_BE

Public Class frmAdm_Valija
    Public p_CodViaje As String
    Public p_FchViaje As Date
    Public p_NroValija As String
    Private ReadOnly _V_ValijaBL As New V_ValijaBL()
    Private ReadOnly _Mani As New ManifiestoBL()

    Private Sub frmAdm_Valija_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler ModAdm_Valija1.cmdNew.Click, AddressOf prl_Button_Nuevo
        AddHandler ModAdm_Valija1.cmdEditar.Click, AddressOf prl_Button_Editar
        AddHandler ModAdm_Valija1.cmdDel.Click, AddressOf prl_Button_Eliminar
        ModAdm_Valija1.GridControl1.DataSource = _V_ValijaBL.pr_ListarValijas(p_CodViaje)
        ModAdm_Valija1.gCodViaje.EditValue = p_CodViaje
        ModAdm_Valija1.gCodViaje.Properties.ReadOnly = True
        ModAdm_Valija1.gFchViaje.EditValue = p_FchViaje
        ModAdm_Valija1.gFchViaje.Properties.ReadOnly = True
        ModAdm_Valija1.gNroValija.EditValue = p_NroValija
    End Sub

    Private Sub prl_Button_Eliminar()
        If ModAdm_Valija1.GridView1.RowCount > 0 Then
            If DevExpress.XtraEditors.XtraMessageBox.Show(" Desea Eliminar el Registro ", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = System.Windows.Forms.DialogResult.Yes Then
                Dim _V_Valija As New V_ValijaBL
                Dim _V_ValijaBE As New V_ValijaBE
                Dim row As DataRow = TryCast(ModAdm_Valija1.GridView1.GetDataRow(ModAdm_Valija1.GridView1.GetSelectedRows()(0)), DataRow)
                _V_ValijaBE.CorrelativoValija = row("ValijaCorrelativo")
                _V_ValijaBE.CodViaje = p_CodViaje
                If _V_Valija.pr_EliminarValija(_V_ValijaBE) Then
                    ModAdm_Valija1.GridControl1.DataSource = _V_ValijaBL.pr_ListarValijas(p_CodViaje)
                End If
            End If
        End If
    End Sub

    Private Sub prl_Button_Editar()
        If ModAdm_Valija1.GridView1.RowCount > 0 Then
            Using sfrmValijaNuevo As New frmAdm_ValijaEdicion()
                sfrmValijaNuevo.p_opcion = 2
                ' Editar Registro
                sfrmValijaNuevo.p_CodViaje = p_CodViaje
                Dim row As DataRow = TryCast(ModAdm_Valija1.GridView1.GetDataRow(ModAdm_Valija1.GridView1.GetSelectedRows()(0)), DataRow)
                sfrmValijaNuevo.p_CorrelativoValija = row("ValijaCorrelativo")
                sfrmValijaNuevo.ModAdm_ValijaEdicion1.cbTipoValija.EditValue = row("TipoValija")
                sfrmValijaNuevo.ModAdm_ValijaEdicion1.gRemitenteValija.EditValue = row("RemitenteValija")
                sfrmValijaNuevo.ModAdm_ValijaEdicion1.gDestinatarioValija.EditValue = row("DestinatarioValija")
                sfrmValijaNuevo.ModAdm_ValijaEdicion1.gObsValija.EditValue = row("ObsValija")
                Dim oDialogResult As System.Windows.Forms.DialogResult
                oDialogResult = sfrmValijaNuevo.ShowDialog()
                If oDialogResult = System.Windows.Forms.DialogResult.OK Then
                    ModAdm_Valija1.GridControl1.DataSource = _V_ValijaBL.pr_ListarValijas(p_CodViaje)
                End If
            End Using
        End If
    End Sub

    Private Sub prl_Button_Nuevo()
        Using sfrmValijaEdicion As New frmAdm_ValijaEdicion()
            sfrmValijaEdicion.p_opcion = 1
            ' Añadir Nuevo Registro
            sfrmValijaEdicion.p_CorrelativoValija = ModAdm_Valija1.GridView1.RowCount + 1
            sfrmValijaEdicion.p_CodViaje = p_CodViaje
            Dim oDialogResult As System.Windows.Forms.DialogResult
            oDialogResult = sfrmValijaEdicion.ShowDialog()
            If oDialogResult = System.Windows.Forms.DialogResult.OK Then
                ModAdm_Valija1.GridControl1.DataSource = _V_ValijaBL.pr_ListarValijas(p_CodViaje)
            End If
        End Using
    End Sub

    Private Sub cmdaceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdaceptar.Click
        If _Mani.pr_ActualizarNroValija(p_CodViaje, ModAdm_Valija1.gNroValija.EditValue) Then
        End If
        Close()
    End Sub

End Class